<style lang="scss" scoped>
	.content {
		width: 100%;
		background-color: white;
		padding: 30rpx 0;
	}

	.list {
		padding: 25rpx;
		border-bottom: 1px solid #ccc;
		align-items: flex-start;
		color: #737373;

		.red {
			transform: translateY(6rpx);
		}

		.textarea {
			width: 460rpx;
			height: 120rpx;
			font-size: 28rpx;
		}

		.mic {
			height: 120rpx;
			width: 80rpx;
			border-left: 1px solid #ccc;
			padding-left: 20rpx;
		}

		.ipt {
			width: 550rpx;
		}

		.uploadfile {
			width: 550rpx;

			.btns {
				width: 100%;

				.btn {
					width: 152rpx;
					height: 64rpx;

					border: 2rpx solid #bfbfbf;
					border-radius: 34rpx;
				}
			}
		}

		.record {
			width: 550rpx;
		}
	}

	.footer {
		height: 160rpx;
		width: 750rpx;
		padding: 30rpx;

		background-color: white;

		.btn {
			width: 320rpx;
			height: 88rpx;
			border-radius: 44rpx;
		}
	}
</style>

<template>
	<view class="content">
		<view class="f34 bold" style="padding:0 30rpx;border-bottom: 1px solid #ccc;padding-bottom: 20rpx;">多人协助</view>
		<scroll-view scroll-y="true" style="max-height:80vh;">
			<view class="list between-flex f28">
				<view class="align-flex">
					协助时间
				</view>
				<view class="align-flex " style="width: 550rpx;">
					{{date}}
				</view>
			</view>
			<view class="list between-flex f28">
				<view class="align-flex">
					申请人
				</view>
				<view class="align-flex " style="width: 550rpx;">
					{{username}}
				</view>
			</view>
			<view v-for="item,index in user" :key="index">
				<view class="f28  between-flex"
					style="margin-top:50rpx;padding:0 30rpx;border-bottom: 1px solid #ccc;padding-bottom: 20rpx;">
					<view class="bold">协作人{{index+1}}</view>
					<view class="c666" @click="user.splice(index,1)">
						<u-icon name="trash-fill" color="#666" size="38"></u-icon>删除协作人
					</view>
				</view>


				<view class="list between-flex f28">
					<view class="align-flex">
						协作人
					</view>
					<view class="align-flex " style="width: 550rpx;">
						{{item.name}}
					</view>
				</view>
				<view class="list between-flex f28">
					<view class="align-flex">
						协作事务
					</view>
					<view class="align-flex ">
						<textarea style="width:550rpx;" class="textarea" v-model="user[index].content" maxlength="-1"
							placeholder="请填写协作说明" />

					</view>
				</view>
			</view>

			<view class="footer between-flex">
				
					<view style="border: 2rpx solid #409eff;" class="btn  blue center-flex f32 bold" @click="$navTo(PagesCourseRouterConfig.ChoosePerson+'?type=2')">
						添加协作人
					</view>
				
				<view class="btn bgblue cfff center-flex f32 bold" @click="submit">多人协助</view>
			</view>
		</scroll-view>

	</view>
</template>

<script>
	import PagesCourseRouterConfig from '@/pagesCourse/routerConfig.js'
	export default {
		props: {
			orderNum: {
				default: ''
			}
		},
		data() {
			return {
				PagesCourseRouterConfig,
				head: this.$head,
				date: '',
				username: '',
				users: [],
				user: []
			}
		},
		created() {
			
			this.date = this.$getDate()
			this.username = uni.getStorageSync('username')
			
			uni.$on('choosePerson',(data)=>{
				data.content=''
				let list=this.user
				let flag=true
				list.forEach(item=>{
					if(item.id==data.id){
						flag=false
					}
				})
				if(!flag) {
					
				} else {
					this.user.push(data);
				}
			})
		},
		beforeDestroy() {
			uni.$off('choosePerson')
		},
		methods: {
			choose(e, type, list) {

				switch (type) {

					case 2:
						if (this.user.indexOf(list[e.detail.value]) != -1) {
							this.$msg('该协作人已存在！')
						} else {
							this.user.push(list[e.detail.value]);
						}

						break;

				}

			},
			submit() {

				if (this.user.length == 0) {
					this.$msg('请添加协作人！')
					return
				}
				var assist = []
				this.user.forEach((item,index)=> {
					if(!item.content){
						this.$msg(`协作人${index+1}未填写协作说明`)
						return
					}
					assist.push({
						sendUser: item.value,
						content: item.content
					})
				})
				if(this.user.length==assist.length){
					this.$showloading()
					this.$pop.ajaxPost('/wechat/order/assist',{
						assist:JSON.stringify(assist),
						orderNum:this.orderNum
					}).then(res=>{
						uni.hideLoading()
						if (res.code == 0) {
							this.$msg('提交成功')
							this.$emit('submit')
						} else {
							this.$msg(res.msg)
						}
					})
				}
			}

		}
	}
</script>
